/*
 * StyledDocument.cpp  0.4.0 / Dec 03, 2010
 *
 * Copyright (c) 2010 - 2011, cute4j.com and contributors.
 *
 * This software is licensed under the LGPL version 2.1 license.
 * A copy of this license is included in the file LICENSE-LGPL.txt.
 */
#include "StyledDocument.h"

// StyledDocument :: Public Constructor. ---------------------------------------

/*!
 * \brief Constructs new StyledDocument object.
 *
 * \param documentDelegate the document delegate
 */
StyledDocument::StyledDocument(TextDocumentDelegate *documentDelegate)
  : QTextDocumentAdapter(documentDelegate)
{
  // empty constructor body
}

// StyledDocument :: Overridden Member Functions. ------------------------------

/*!
 * \brief Returns document's text.
 *
 * \return document's text
 */
QString StyledDocument::getText() const
{
  return QTextDocumentAdapter::toHtml();
}

/*!
 * \brief Sets document's text.
 *
 * \param text the text to be set
 */
void StyledDocument::setText(const QString &text)
{
  QTextDocumentAdapter::setHtml(text);
  setModified(false);
  emit textSet();
}

/*!
 * \brief Appends text.
 *
 * \param text the text to be appended
 */
void StyledDocument::appendText(const QString &text)
{
  QTextCursor cursor(this);
  cursor.beginEditBlock();
  cursor.movePosition(QTextCursor::End);
  cursor.insertHtml(text);
  cursor.endEditBlock();
  emit textAppended();
}

/*!
 * \inheritDoc
 */
QVariant StyledDocument::loadResource(int type, const QUrl &name)
{
  // TODO: implement resource loading
  return QTextDocumentAdapter::loadResource(type, name);
}
